

import { mergeOptions } from "./util";

export function initGlobalAPI(Vue) {
    Vue.options = {
        _base: Vue
    }

    Vue.mixin = function (mixin) {
        this.options = mergeOptions(this.options, mixin)
    }


    Vue.extend = function (options) {

        function Sub(options = {}) {
            this._init(options)
        }
        Sub.prototype = Object.create(Vue.prototype)
        Sub.prototype.constructor = Sub // 使用object.create后  sub的prototype.constructor也变成了Vue
        Sub.options = mergeOptions(Vue.options, options)
        return Sub

    }

    Vue.options.components = {}
    Vue.component = function (name, definition) {
        definition = typeof definition === 'function' ? definition : Vue.extend(definition)
        Vue.options.components[name] = definition
    }
}
